package br.trainee.web.componentes;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import br.trainee.web.util.ResponseWrapper;

public class SubmenuTag extends BodyTagSupport{

	private String customClassSub;
	private String customTextClassSub;
	private String hrefSub;
	private String valueSub;
	private String iconsSub;
	private boolean disabledSub;
	
	@Override
	public int doEndTag() throws JspException {
		
		JspWriter saida = pageContext.getOut();
		String corpoSubmenu = getBodyContent().getString();
		
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();		
		HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();

		request.setAttribute("customClassSub", customClassSub);
		request.setAttribute("customTextClassSub", customTextClassSub);
		request.setAttribute("hrefSub", hrefSub);
		request.setAttribute("valueSub", valueSub);
		request.setAttribute("iconsSub", iconsSub);
		request.setAttribute("disabledSub", disabledSub);
		request.setAttribute("corpoSubmenu", corpoSubmenu);
		
		ResponseWrapper responseWrapper = new ResponseWrapper(response);
		
		RequestDispatcher req = request.getRequestDispatcher("/resources/componentes-jsp/submenu.jsp");
		
		try {
			
			req.include(request, responseWrapper);
			String conteudoComponente = responseWrapper.getString();
			
			saida.println(conteudoComponente);
			
		}catch(IOException io){
			
			io.printStackTrace();
			
		} catch (ServletException s) {
			
			s.printStackTrace();
		}
		
		return super.doEndTag();
	}

	public String getCustomClassSub() {
		return customClassSub;
	}

	public void setCustomClassSub(String customClassSub) {
		this.customClassSub = customClassSub;
	}

	public String getCustomTextClassSub() {
		return customTextClassSub;
	}

	public void setCustomTextClassSub(String customTextClassSub) {
		this.customTextClassSub = customTextClassSub;
	}

	public String getHrefSub() {
		return hrefSub;
	}

	public void setHrefSub(String hrefSub) {
		this.hrefSub = hrefSub;
	}

	public String getValueSub() {
		return valueSub;
	}

	public void setValueSub(String valueSub) {
		this.valueSub = valueSub;
	}

	public String getIconsSub() {
		return iconsSub;
	}

	public void setIconsSub(String iconsSub) {
		this.iconsSub = iconsSub;
	}

	public boolean isDisabledSub() {
		return disabledSub;
	}

	public void setDisabledSub(boolean disabledSub) {
		this.disabledSub = disabledSub;
	}
			
}
